/*
@author: stanfor
@date: 2022/8/7 10:20
@Version: 1.0
@last modify time : 2022/8/7 10:20
*/

import { createSlice } from '@reduxjs/toolkit';
import { getLoginRequest } from '@S/asyncAction/login';

// 创建一个 Slice
const login = createSlice({
  name: 'login',
  initialState: {
    list: [],
    totals: 0,
  },
  reducers: {

  },
  // extraReducers 字段让 slice 处理在别处定义的 actions，
  // 包括由 createAsyncThunk 或其他 slice 生成的 actions。
  extraReducers(builder) {
    builder
      .addCase(getLoginRequest.fulfilled, (state, {payload}) => {
        console.log('🚀 ~ fulfilled', state, '接受 getMovieData 抛出来的信息: ', payload);
        state.list = payload.data.list;
        state.totals = payload.data.list.length;
      })
      .addCase(getLoginRequest.rejected, (state, err) => {
        console.log('🚀 ~ rejected', err)
      });
  },
});

// 导出方法
// export const { loadDataEnd } = movie.actions;

// 默认导出
export default login.reducer;
